<?php
/*
 * 2021/7/15
 * 11:37
 * User: 2650332702@qq.com
 */

namespace App\Api\Bases;

use App\Api\Services\BlackWhite;
use App\Api\Services\JsonService;
use App\Http\Controllers\Controller;
class BaseController extends Controller
{
    //时间格式化
    public function TimeFormatting($time)
    {
        return date('Y-m-d H:i:s',$time);
    }
    //现在时间
    public function NowTime()
    {
        return date('Y-m-d H:i:s',time());
    }


    public function redisLimit($key = '',  $count = 3)
    {
        $keyRes = cache($key) ?? 0;
        if ($keyRes>$count) {
            dd(['code' => 0, 'msg' => '您的操作太频繁,请稍后再试', 'data' =>'']);
        } else {
            $keyRes++;
            $res = cache([$key=>$keyRes],5);
            if (!$res) dd(['code' => 0, 'msg' => '网络繁忙,请稍后再试', 'data' =>'']);
        }
    }

    public function __construct(){
        $ip = BlackWhite::getClientIp();
        $this->redisLimit('ip_'.$ip);
    }

    //访问错误
    public function getPost()
    {
        return JsonService::fail('访问类型错误');
    }

    


}
